package com.raskasso.opengl.listeners;

import com.raskasso.opengl.renderer.PruebasRenderer;

import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.opengl.GLSurfaceView.Renderer;
import android.opengl.GLU;

public class AcelerometroListener implements SensorEventListener {
	
	private SensorManager mSensorManager;
	private PruebasRenderer pruebasRenderer;
		
	public AcelerometroListener(SensorManager mSensorManager, PruebasRenderer pruebasRenderer) {
		super();
		this.mSensorManager = mSensorManager;
		this.pruebasRenderer=pruebasRenderer;
	}

	@Override
	public void onAccuracyChanged(Sensor sensor, int accuracy) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onSensorChanged(SensorEvent event) {
		 /* 1 radian = 57.2957795 degrees */
	    /* [0] : yaw, rotation around z axis
	     * [1] : pitch, rotation around x axis
	     * [2] : roll, rotation around y axis */
//        pruebasRenderer.centerx=event.values[1] * 57.2957795f;
//		pruebasRenderer.centerz=event.values[0] * 57.2957795f;
//		pruebasRenderer.centery=event.values[2] * 57.2957795f; 		
		
	}
	
	public void registerListener(){
		 mSensorManager.registerListener(this, mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD), SensorManager.SENSOR_DELAY_GAME);
         mSensorManager.registerListener(this, mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_GAME);
	}
	
	public void unregisterListener(){
		mSensorManager.unregisterListener(this);
	}
	

}
